if (!jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.userMgt.groups.GroupDetail")) {
    /**
    *
    **/
    jsx3.lang.Class.defineClass("tibco.admin.enterpriseAssets.userMgt.groups.GroupDetail",
            jsx3.gui.LayoutGrid,
            null,
            function (groupDetail) {

                groupDetail.prototype.initialize = function() {
                    // set the window instance id
                    if (jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.userMgt.window.Window")) {
                        this.window = this.getAncestorOfType(tibco.admin.enterpriseAssets.userMgt.window.Window)
                        if (this.window) {
                            this.setWindowId(this.window.getId());
                        }
                    }
                    // set the matrix
                    this.userList = this.getDescendantOfName("mtxUserList_24_G");
                    //Load sub components
                    this.searchBarObj = null;
                    // this.loadSubComponent("paneAddUsers_24_G", "tibco/admin/enterpriseAssets/userMgt/window/groups/ui/groupSearchBar.xml");
                    tibco.admin.Main.loadUIResource(this.getDescendantOfName("paneAddUsers_24_G") , "tibco.admin", "tibco/admin/enterpriseAssets/userMgt/window/groups/ui/groupSearchBar.xml",  true);

                    this.groupId = "";
                    this.groupName = "";
                    this.isWriteable = false;

                    this.editBtn = this.getDescendantOfName("btnEdit_24_G");
                    this.saveBtn = this.getDescendantOfName("btnSave_24_G");
                    this.cancelBtn = this.getDescendantOfName("btnCancel_24_G");
                    this.removeBtn = this.getDescendantOfName("btnMask_24_C");
					 this.detailUsers = this.getDescendantOfName("blkGroupUsers_24_G");
                    var me = this;
                    this.editBtn.showEdit = function() {
                        me.showEdit();
                    }
                    this.cancelBtn.cancelEdit = function() {
                        me.cancelEdit();
                    }
                    this.saveBtn.doSave = function() {
                        me.doSave();
                    }

                    this.removeBtn.doRemove = function(curRecId) {
                        var uid = me.userList.getRecord(curRecId).username;
                        me.callremoveUsersFromGroup(uid);
                    }

					this.passedItems["groupName"] = false;//070818

                }

				/**
				 *   set the current window ID
				 *   @param strId {string} The window id
				 **/
                groupDetail.prototype.setWindowId = function(strId) {
                    this.windowId = strId
                }

                /**
				 *   get the current window ID
				 *   @return {string} The window id
				 **/
                groupDetail.prototype.getWindowId = function() {
                    return this.windowId
                }

                /**
                 *	 The call back function of display the detail event
				 *
                 **/
                groupDetail.prototype.setDetails = function(objEvent) {
                    try {
                        //Set details only if the message is for you
                        if (objEvent.windowId == this.getWindowId()) {
                            this.cancelEdit();
							this.groupId = objEvent.groupId;
                            this.groupName = objEvent.groupName;
                            this.isWriteable = objEvent.isWriteable;
                            this.getDescendantOfName("lblGroupIDContent_24_G").setText(objEvent.groupName, false);
                            this.getDescendantOfName("lblGroupDescContent_24_G").setText(objEvent.groupDesc, false);
                            this.callgetAllUsersInGroup();

							 if (objEvent.isRealmWriteable == true) {
                                if (objEvent.isWriteable == true) {
                                    this.editBtn.setEnabled(jsx3.gui.Form.STATEENABLED, true);
                                    this.getDescendantOfName("btnAddGroups_24_J_1").setEnabled(jsx3.gui.Form.STATEENABLED, true);
                                } else {
                                    this.editBtn.setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                                    this.getDescendantOfName("btnAddGroups_24_J_1").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                                }
                            } else {
                                this.editBtn.setEnabled(jsx3.gui.Form.STATEDISABLED, true);
								                this.getDescendantOfName("btnAddGroups_24_J_1").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                            }
                            this.repaint();
                        }
                    } catch(ex) {
                        tibco.admin.Main.logException(ex, "Error in tibco.admin.enterpriseAssets.userMgt.groups.GroupDetail#setDetails");
                    }
                }


                groupDetail.prototype.subscribeAll = function() {
					var me = this;
					setTimeout(function(){
						tibco.admin.PubSub.subscribe(tibco.admin.enterpriseAssets.userMgt.EventID.MASTER_ROW_SELECTED, me, me.setDetails)
						},0);
                }

                groupDetail.prototype.unsubscribeAll = function() {
                    tibco.admin.PubSub.unsubscribe(tibco.admin.enterpriseAssets.userMgt.EventID.MASTER_ROW_SELECTED, this);
                }

				/**
				 * Load sub component
				 **/
                groupDetail.prototype.loadSubComponent = function(nodeName, path) {
                    var domeNode = this.getDescendantOfName(nodeName)
                    // Load only if dose not exists
                    if (domeNode.getChildren().length == 0) {
                        tibco.admin.Main.loadUIResourceAsync(domeNode, "tibco.admin", path, this, this.isLoaded, true, true);
                    }
                }

				/**
				 * The call back function of loadSubComponent
				 **/
                groupDetail.prototype.isLoaded = function(msg) {
                    this.searchBarObj = msg.obj;
                    if (this.isWriteable) {
                        this.editBtn.setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                        this.searchBarObj.getDescendantOfName("paneMainSearch_24_J_1").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    }
                    else {
                        this.editBtn.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                        this.searchBarObj.getDescendantOfName("paneMainSearch_24_J_1").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    }
                }

				/**
				 *	Change to edit mode
				 **/
                groupDetail.prototype.showEdit = function() {
                    var parent = this.editBtn.getAncestorOfName("lytGroupDetail_24_G");
                    // hide two labels
                    var lblGroupId = parent.getDescendantOfName("lblGroupIDContent_24_G");
                    var lblGroupDesc = parent.getDescendantOfName("lblGroupDescContent_24_G");
                    lblGroupId.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    lblGroupDesc.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    // show two textbox
                    parent.getDescendantOfName("txtGroupIDContent_24_G").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    parent.getDescendantOfName("txtGroupDescContent_24_G").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    parent.getDescendantOfName("txtGroupIDContent_24_G").setValue(lblGroupId.getText());
                    parent.getDescendantOfName("txtGroupDescContent_24_G").setValue(lblGroupDesc.getText());
                    //hide edit button
                    this.editBtn.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    // show save and cancel buttons
                    parent.getDescendantOfName("btnSave_24_G").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    parent.getDescendantOfName("btnCancel_24_G").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    this.valiGroupName(parent.getDescendantOfName("txtGroupIDContent_24_G"));
                    this.valiGroupDesc(parent.getDescendantOfName("txtGroupDescContent_24_G"));
                }

				/**
				 *	Change to view mode
				 **/
                groupDetail.prototype.cancelEdit = function() {
                    var parent = this.editBtn.getAncestorOfName("lytGroupDetail_24_G");
                    // show two labels
                    parent.getDescendantOfName("lblGroupIDContent_24_G").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    parent.getDescendantOfName("lblGroupDescContent_24_G").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    //show edit button
                    this.editBtn.setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    // hide two textbox
                    parent.getDescendantOfName("txtGroupIDContent_24_G").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    parent.getDescendantOfName("txtGroupDescContent_24_G").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    // hide save and cancel buttons
                    parent.getDescendantOfName("btnSave_24_G").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    parent.getDescendantOfName("btnCancel_24_G").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                }

				/**
				 * Save the group info
				 **/
                groupDetail.prototype.doSave = function() {
                    this.calleditGroup();
                }


                // ============== call web service to get all users in one group ==============
				/**
				 *  Get all users in a group - webservice call
				 **/
                groupDetail.prototype.callgetAllUsersInGroup = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/enterpriseAssets/userMgt/window/groups/rules/getAllUsersInGroup.xml", "getAllUsersInGroup", "Get all users in group");
                    //subscribe and call
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.ongetAllUsersInGroupSuccess);
                    //objService.subscribe(jsx3.net.Service.ON_ERROR, this, this.ongetAllUsersInGroupError);
                    //objService.subscribe(jsx3.net.Service.ON_INVALID, this, this.ongetAllUsersInGroupInvalid);
                    objService.groupId = this.groupId;
                    objService.groupName = this.groupName;
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getUserMgtEndpointURL());
                    objService.doCall();
                }

                groupDetail.prototype.ongetAllUsersInGroupSuccess = function(objEvent) {
                    var sourceXML = objEvent.target.getInboundDocument();
                    this.userList.setSourceXML(sourceXML);
                    this.userList.repaint();
                };

                groupDetail.prototype.ongetAllUsersInGroupError = function(objEvent) {
                    var myStatus = objEvent.target.getRequest().getStatus();
                    tibco.admin.util.Log.USERMGT.error("Error, The service call failed. The HTTP Status code is: " + myStatus);
                };

                groupDetail.prototype.ongetAllUsersInGroupInvalid = function(objEvent) {
                    tibco.admin.util.Log.USERMGT.error("Invalid, The following message node just failed validation:\n\n" + objEvent.message);
                };
                // ---------------------------------------------------------------------



                /**
				 *	Edit group info - webservice call
				 **/
                groupDetail.prototype.calleditGroup = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/enterpriseAssets/userMgt/window/groups/rules/editGroup.xml", "editGroup", "Edit Group");

                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.oneditGroupSuccess);
                    //objService.subscribe(jsx3.net.Service.ON_ERROR, this, this.oneditGroupError);
                    //objService.subscribe(jsx3.net.Service.ON_INVALID, this, this.oneditGroupInvalid);
                    objService.groupId = this.groupId;
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getUserMgtEndpointURL());
                    objService.doCall();
                };

                groupDetail.prototype.oneditGroupSuccess = function(objEvent) {
                    var msg = new Object();
                    msg.subject = tibco.admin.enterpriseAssets.userMgt.EventID.EDIT_ITEM_SUCCESS
                    msg.windowId = this.getWindowId();
                    tibco.admin.PubSub.publish(msg);
                };

                groupDetail.prototype.oneditGroupError = function(objEvent) {
                    var myStatus = objEvent.target.getRequest().getStatus();
                    tibco.admin.util.Log.USERMGT.error("Error, The service call failed. The HTTP Status code is: " + myStatus);
                };

                groupDetail.prototype.oneditGroupInvalid = function(objEvent) {
                    tibco.admin.util.Log.USERMGT.error("Invalid, The following message node just failed validation:\n\n" + objEvent.message);
                };
                //-----------------------------------------------------------------------


                /**
				 *	  Remove users from a group
				 **/
                groupDetail.prototype.callremoveUsersFromGroup = function(userid) {
                    var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/enterpriseAssets/userMgt/window/groups/rules/removeUsersFromGroup.xml", "removeUsersFromGroup", "Remove User From Group");

                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.onremoveUsersFromGroupSuccess);
                    //objService.subscribe(jsx3.net.Service.ON_ERROR, this, this.onremoveUsersFromGroupError);
                    //objService.subscribe(jsx3.net.Service.ON_INVALID, this, this.onremoveUsersFromGroupInvalid);
                    objService.groupId = this.groupId;
                    objService.groupName = this.groupName;
                    objService.userid = userid;
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getUserMgtEndpointURL());
                    objService.doCall();
                };

                groupDetail.prototype.onremoveUsersFromGroupSuccess = function(objEvent) {
                    this.callgetAllUsersInGroup();
                };

                groupDetail.prototype.onremoveUsersFromGroupError = function(objEvent) {
                    var myStatus = objEvent.target.getRequest().getStatus();
                    tibco.admin.util.Log.USERMGT.error("Error, The service call failed. The HTTP Status code is: " + myStatus);
                };

                groupDetail.prototype.onremoveUsersFromGroupInvalid = function(objEvent) {
                    tibco.admin.util.Log.USERMGT.error("Invalid, The following message node just failed validation:\n\n" + objEvent.message);
                };

				/**
				*070818
				* if user doesn't fishish all the required fields, the "save" button will be disabled.
				**/
				groupDetail.prototype.passedItems = {};

                groupDetail.prototype.valiGroupName = function(obj, strValue) {
                    this.passedItems["groupName"] = tibco.admin.util.Validation.doValidateNotEmptyNoWhSpace(obj, strValue, tibco.admin.Main.getServer().getDynamicProperty("@@comName_24"));
//					this.passedItems["groupDesc"] = tibco.admin.util.Validation.trimAll(this.getDescendantOfName("txtGroupDescContent_24_G").getValue())?true:false;
					this.enableSaveBtn4Add();
                };

                groupDetail.prototype.valiGroupDesc = function(obj, strValue) {
//                    this.passedItems["groupDesc"] = tibco.admin.util.Validation.doValidateNoWhSpace(obj, strValue, tibco.admin.Main.getServer().getDynamicProperty("@@comDesc_24"));
//					this.passedItems["groupName"] = tibco.admin.util.Validation.trimAll(this.getDescendantOfName("txtGroupIDContent_24_G").getValue())?true:false;
//					this.enableSaveBtn4Add();
				};

                groupDetail.prototype.enableSaveBtn4Add = function() {
					var allPassed = true;
					for (var item in this.passedItems) {
						if(!this.passedItems[item]) allPassed = false;
					}
					if(allPassed) this.getDescendantOfName("btnSave_24_G").setEnabled(jsx3.gui.Form.STATEENABLED, true);
					else this.getDescendantOfName("btnSave_24_G").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
				}


            });
}
